<!doctype html><html><head>
<title>A canvas shadow path example</title>

<script src="../canvas.vml.js"></script>
<script src="../canvas.js"></script>

<script>
function oncanvasready() {
    drawShape(document.getElementById('vmlcanvas'));
}
function matrix() {
    drawShape(document.getElementById('vmlcanvas'), 1);
}
var globalAlpha = 1.0
function switchAlpha() {
    globalAlpha -= 0.2;
    drawShape(document.getElementById('vmlcanvas'));
}
var shadowBlur = 2;
function switchBlur() {
    shadowBlur += 2;
    drawShape(document.getElementById('vmlcanvas'));
}

function drawShape(canvas, matrix){
    if (!canvas.getContext){ return; }

    var ctx = canvas.getContext('2d');

    ctx.clear();
    if (matrix) {
        ctx.translate(-10, 5);
        ctx.scale(1.2, 0.8);
        ctx.rotate(5 * Math.PI / 180);
    }
    ctx.shadowBlur = shadowBlur + 4;
    ctx.shadowOffsetX = 10;
    ctx.shadowOffsetY = 10;
    ctx.shadowColor = "gray";
    ctx.lineWidth = 3;
    ctx.globalAlpha = globalAlpha;

    var grad1 = ctx.createLinearGradient(105,0, 200,100);
    grad1.addColorStop(0,    'yellow');
    grad1.addColorStop(0.25, 'red');
    grad1.addColorStop(0.75, 'blue');
    grad1.addColorStop(1,    'limegreen');

    var grad2 = ctx.createRadialGradient(50,50,10,50,50,50);
    grad2.addColorStop(0,    'yellow');
    grad2.addColorStop(0.25, 'red');
    grad2.addColorStop(0.75, 'blue');
    grad2.addColorStop(1,    'limegreen');

    // linear grad box
    ctx.fillStyle = grad1;
    ctx.fillRect(105,0, 100,100);

    // skyblue box
    ctx.fillStyle = "skyblue";
    ctx.fillRect(105,100+50, 100,100);

    // radial grad oval
    ctx.beginPath();
    ctx.arc(50, 50, 50, 0, Math.PI*2, false);
    ctx.fillStyle = grad2;
    ctx.fill();

    // gold oval
    ctx.beginPath();
    ctx.arc(50, 150+50, 50, 0, Math.PI*2, false);
    ctx.fillStyle = "gold";
    ctx.fill();

    // lines
    ctx.beginPath();
    ctx.moveTo(150, 0);
    ctx.lineTo(0, 150);
    ctx.strokeStyle = "rgba(12%,34%,56%,0.4)";
    ctx.stroke();

    ctx.beginPath();
    ctx.moveTo(200, 0);
    ctx.lineTo(0, 200);
    ctx.strokeStyle = "rgba(12%,34%,56%,0.4)";
    ctx.stroke();

    ctx.beginPath();
    ctx.moveTo(250, 0);
    ctx.lineTo(0, 250);
    ctx.strokeStyle = "rgba(12%,34%,56%,0.4)";
    ctx.stroke();

    ctx.beginPath();
    ctx.moveTo(300, 0);
    ctx.lineTo(0, 300);
    ctx.strokeStyle = "rgba(12%,34%,56%,0.4)";
    ctx.stroke();
}
</script>
    <style type="text/css">
      body { margin: 20px; font-family: arial,verdana,helvetica; background: #fff;}
      h1 { font-size: 140%; font-weight:normal; color: #036; border-bottom: 1px solid #ccc; }
      canvas { border: 2px solid #000; float: left; margin-right: 20px; margin-bottom: 20px; }
      pre { float:left; display:block; background: rgb(238,238,238); border: 1px dashed #666; padding: 15px 20px; margin: 0 0 10px 0; }
    </style>
  </head>
  <body>
    <h1>A canvas <code>shadow path</code> example</h1>
    <div>
      <input type="button" value="matrix effect" onclick="matrix()" />
      <input type="button" value="alpha -0.2" onclick="switchAlpha()" />
      <input type="button" value="blur +2" onclick="switchBlur()" />
      <br />
      <canvas id="vmlcanvas" class="vml" width="300" height="300"></canvas>
      <pre>
      &lt;canvas id="vmlcanvas" class="vml" width="300" height="300"&gt;&lt;/canvas&gt;

function oncanvasready() {
    drawShape(document.getElementById('vmlcanvas'));
}
function matrix() {
    drawShape(document.getElementById('vmlcanvas'), 1);
}
var globalAlpha = 1.0
function switchAlpha() {
    globalAlpha -= 0.2;
    drawShape(document.getElementById('vmlcanvas'));
}
var shadowBlur = 3;
function switchBlur() {
    shadowBlur += 3;
    drawShape(document.getElementById('vmlcanvas'));
}

function drawShape(canvas, matrix){
    if (!canvas.getContext){ return; }

    var ctx = canvas.getContext('2d');

    ctx.clear();
    if (matrix) {
        ctx.translate(-10, 5);
        ctx.scale(1.2, 0.8);
        ctx.rotate(5 * Math.PI / 180);
    }
    ctx.shadowBlur = shadowBlur;
    ctx.shadowOffsetX = 10;
    ctx.shadowOffsetY = 10;
    ctx.shadowColor = "gray";
    ctx.lineWidth = 3;
    ctx.globalAlpha = globalAlpha;

    var grad1 = ctx.createLinearGradient(105,0, 200,100);
    grad1.addColorStop(0,    'yellow');
    grad1.addColorStop(0.25, 'red');
    grad1.addColorStop(0.75, 'blue');
    grad1.addColorStop(1,    'limegreen');

    var grad2 = ctx.createRadialGradient(50,50,10,50,50,50);
    grad2.addColorStop(0,    'yellow');
    grad2.addColorStop(0.25, 'red');
    grad2.addColorStop(0.75, 'blue');
    grad2.addColorStop(1,    'limegreen');

    // linear grad box
    ctx.fillStyle = grad1;
    ctx.fillRect(105,0, 100,100);

    // skyblue box
    ctx.fillStyle = "skyblue";
    ctx.fillRect(105,100+50, 100,100);

    // radial grad oval
    ctx.beginPath();
    ctx.arc(50, 50, 50, 0, Math.PI*2, false);
    ctx.fillStyle = grad2;
    ctx.fill();

    // gold oval
    ctx.beginPath();
    ctx.arc(50, 150+50, 50, 0, Math.PI*2, false);
    ctx.fillStyle = "gold";
    ctx.fill();

    // lines
    ctx.beginPath();
    ctx.moveTo(150, 0);
    ctx.lineTo(0, 150);
    ctx.strokeStyle = "rgba(12%,34%,56%,0.4)";
    ctx.stroke();

    ctx.beginPath();
    ctx.moveTo(200, 0);
    ctx.lineTo(0, 200);
    ctx.strokeStyle = "rgba(12%,34%,56%,0.4)";
    ctx.stroke();

    ctx.beginPath();
    ctx.moveTo(250, 0);
    ctx.lineTo(0, 250);
    ctx.strokeStyle = "rgba(12%,34%,56%,0.4)";
    ctx.stroke();

    ctx.beginPath();
    ctx.moveTo(300, 0);
    ctx.lineTo(0, 300);
    ctx.strokeStyle = "rgba(12%,34%,56%,0.4)";
    ctx.stroke();
}
      </pre>
    </div>
  </body>
</html>
